﻿using System;
using System.Threading.Tasks;

namespace Chapter1_13
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            Task<int[]> parent = Task.Run(() => {
                int[] results = new int[3];
                TaskFactory tf = new TaskFactory(TaskCreationOptions.AttachedToParent, TaskContinuationOptions.ExecuteSynchronously);

                tf.StartNew(() => { results[0] = 10; });
                tf.StartNew(() => { results[1] = 20; });
                tf.StartNew(() => { results[2] = 30; });
                return results;
            });

            Task final = parent.ContinueWith((i) => {
                foreach (int item in i.Result)
	            {
		            Console.WriteLine("Task result {0}", item);
	            }
            });
            
            final.Wait(); 
            Console.ReadLine();
        }
    }
}
